class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        if not s:
            return 0
        set1=set()
        n=len(s)
        r,ans=0,0
        set1.add(s[0])
        for i in range(len(s)):
            if i!=0:
                set1.remove(s[i - 1])

            while r+1<n and s[r+1] not in set1:

                set1.add(s[r+1])
                r += 1
            ans=max(ans,r-i+1)
        return ans


if __name__ == '__main__':
    s=Solution()
    ans=s.lengthOfLongestSubstring("abcabcbb")
    print(ans)